package com.qihoo360.mobilesafe.opti.powerctl.ui.widget;

import com.qihoo360.mobilesafe.opti.powerctl.R;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;

public class BtyAniView extends FrameLayout {

	private boolean a = true;
	private boolean b = false;

	private TranslateAnimation mChargingTranslateAnimation;
	private int d = 0;
	private int e = 0;
	private int f = 0;
	private int g = 0;
	private int h = 0;
	private Handler mHandler;// i

	private ImageView mBatteryPower;// j
	private ImageView mBatteryBox;// k
	private ImageView mBatteryStar;// l
	private int m;

	public BtyAniView(Context context) {
		super(context);
		this.m = 100;
		inflate(context, R.layout.bty_ani_view, this);
		mBatteryPower = (ImageView) findViewById(R.id.img_ani_battery_power);
		mBatteryBox = (ImageView) findViewById(R.id.img_ani_battery_box);
		mBatteryStar = (ImageView) findViewById(R.id.img_ani_battery_star);
		mBatteryStar.setVisibility(View.GONE);
	}

	public BtyAniView(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.m = 100;
		inflate(context, R.layout.bty_ani_view, this);
		mBatteryPower = (ImageView) findViewById(R.id.img_ani_battery_power);
		mBatteryBox = (ImageView) findViewById(R.id.img_ani_battery_box);
		mBatteryStar = (ImageView) findViewById(R.id.img_ani_battery_star);
		mBatteryStar.setVisibility(View.GONE);
	}

	public static int a(BtyAniView view) {
		return view.m;
	}

	public static int a(BtyAniView view, int paramInt) {
		view.h = paramInt;
		return paramInt;
	}

	public static boolean a(BtyAniView view, boolean temp) {
		view.b = temp;
		return temp;
	}

	public static int b(BtyAniView view, int temp) {
		view.f = temp;
		return temp;
	}

	public static ImageView b(BtyAniView view) {
		return view.mBatteryPower;
	}

	public static int c(BtyAniView view) {
		return view.f;
	}

	public static int c(BtyAniView view, int temp) {
		view.d = temp;
		return temp;
	}

	public static int d(BtyAniView view, int temp) {
		view.e = temp;
		return temp;
	}

	public static boolean d(BtyAniView view) {
		return view.b;
	}

	public static int e(BtyAniView view) {
		return view.h;
	}

	public static int e(BtyAniView view, int temp) {
		view.m = temp;
		return temp;
	}

	public static int f(BtyAniView view) {
		return view.g;
	}

	public static ImageView g(BtyAniView view) {
		return view.mBatteryBox;
	}

	public void refreshUI(int paramInt1, int paramInt2) {
		int n = 100;
		if (paramInt1 <= 0)
			n = 0;
		if (n > 100) {
			if (a) {
				a = false;
				Message msg = mHandler.obtainMessage(3, n, paramInt2, null);
				mHandler.sendMessageDelayed(msg, 800);
			}
		} else {
			Message msg = mHandler.obtainMessage(3, n, paramInt2, null);
			mHandler.sendMessageDelayed(msg, 50);
		}
	}

	public void setAlarmArea(Message msg) {
		int n = this.f;
		int i1 = msg.arg2;
		int i2 = 100 - i1;
		int i3 = n * i2 / 100;
		this.e = i3;
		int i4 = this.m;
		int i5 = msg.arg2;
		float f1 = (i4 - i5) / 100.0F;
		// setAnimationAttrs(f1);
		int i6 = msg.arg2;
		this.g = i6;
		int i7 = msg.arg1;
		int i8 = msg.arg2;
		if (i7 >= i8) {
			int i9 = msg.arg1;
			int i10 = msg.arg2;
		} else {
			int i11 = this.e;
			this.d = i11;
			int i12 = this.f;
			int i13 = msg.arg1;
			int i14 = 100 - i13;
			int i15 = i12 * i14 / 100;
			this.e = i15;
			mChargingTranslateAnimation.setAnimationListener(null);
		}
	}

	public void isLowCharging() {
		mBatteryStar.setVisibility(View.VISIBLE);
		mChargingTranslateAnimation = new TranslateAnimation(0f, 0f, 160,
				75);
		mChargingTranslateAnimation.setDuration(2000);
		mChargingTranslateAnimation.setFillEnabled(true);
		mChargingTranslateAnimation.setFillAfter(true);
		mChargingTranslateAnimation.setAnimationListener(new AnimationListener(){

			@Override
			public void onAnimationEnd(Animation animation) {
				mBatteryPower.startAnimation(animation);
			}

			@Override
			public void onAnimationRepeat(Animation animation) {
				
			}

			@Override
			public void onAnimationStart(Animation animation) {
				
			}
			
		});
		mBatteryPower.startAnimation(mChargingTranslateAnimation);
	}

	public void isCharging() {
		mBatteryStar.setVisibility(View.INVISIBLE);
		mChargingTranslateAnimation = new TranslateAnimation(0f, 0f, 100,
				16);
		mChargingTranslateAnimation.setDuration(3000);
		mChargingTranslateAnimation.setFillEnabled(true);
		mChargingTranslateAnimation.setFillAfter(true);
		mChargingTranslateAnimation.setAnimationListener(new AnimationListener(){

			@Override
			public void onAnimationEnd(Animation animation) {
				mBatteryPower.startAnimation(animation);
			}

			@Override
			public void onAnimationRepeat(Animation animation) {
				
			}

			@Override
			public void onAnimationStart(Animation animation) {
				
			}
			
		});
		mBatteryPower.startAnimation(mChargingTranslateAnimation);
	}
	
	public void showBatteryStatus()
	{
		mBatteryStar.setVisibility(View.INVISIBLE);
		mChargingTranslateAnimation = new TranslateAnimation(0f, 0f, 160,
				75);
		mChargingTranslateAnimation.setDuration(2000);
		mChargingTranslateAnimation.setFillEnabled(true);
		mChargingTranslateAnimation.setFillAfter(true);
		mChargingTranslateAnimation.setAnimationListener(new AnimationListener(){

			@Override
			public void onAnimationEnd(Animation animation) {
				
			}

			@Override
			public void onAnimationRepeat(Animation animation) {
			}

			@Override
			public void onAnimationStart(Animation animation) {
				
			}
			
		});
		mBatteryPower.startAnimation(mChargingTranslateAnimation);
	}

	public void setAnimationAttrs(float paramFloat, AnimationListener listener) {
		if (paramFloat <= 16)
			paramFloat = 16;
		mChargingTranslateAnimation = new TranslateAnimation(0f, 0f, 160,
				paramFloat);
		long l1 = (int) Math.abs(2000f * paramFloat);
		mChargingTranslateAnimation.setDuration(2000);
		mChargingTranslateAnimation.setFillEnabled(true);
		mChargingTranslateAnimation.setFillAfter(true);
		mChargingTranslateAnimation.setAnimationListener(listener);
		mBatteryPower.startAnimation(mChargingTranslateAnimation);
	}

	public void stopAnimation() {
		mBatteryPower.clearAnimation();
	}
	
	public void initAnimation()
	{
		mChargingTranslateAnimation = new TranslateAnimation(0f, 0f, 160,
				160);
		mChargingTranslateAnimation.setDuration(2000);
		mChargingTranslateAnimation.setFillEnabled(true);
		mChargingTranslateAnimation.setFillAfter(true);
		mBatteryPower.startAnimation(mChargingTranslateAnimation);
	}
}
